<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form method="post" action="/hesuan">
    <table>

        <tr>
            <td colspan="2"><h2>添加核算检测信息</h2></td>
        </tr>
        <tr>
            <td>姓名</td>
            <td><input type="text" name="assayUser" required></td>
        </tr>
        <tr>
            <td>手机号</td>
            <td><input type="text" name="phone" required></td>
        </tr>
        <tr>
            <td>身份证号</td>
            <td><input type="text" name="cardNum" required></td>
        </tr>
        <tr>
            <td>检测机构</td>
            <td>
                <select name="hospitalId" id="selectHospital" required>
                    <option value="" >-请选择-</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>检测日期</td>
            <td><input type="text" name="assayTime" required pattern="/^\d{4}-\d{2}-\d{2}$/"></td>
        </tr>
        <tr>
            <td colspan="">
                <input type="submit" value="添加">
                <button onclick="javascript:window.location.href='/hesuan/list'">返回</button>
            </td>
        </tr>
    </table>
</form>
<script src="/webjars/jquery/3.4.1/jquery.js"></script>

    <script>
    $(function (){
        //请求后台拿到数据——机构的数据
        $.ajax({
            url:'/hospital',
            type:'get',
            dataType:'json',
            success:function (data){
                console.log(data);
                let optionStr = "<option value=\"\">-请选择机构-</option>";
                for (let i = 0; i < data.length; i++) {
                    optionStr += "<option value=\""+data[i].id+"\">"+data[i].name+"</option>"
                }
                $("#selectHospital").html(optionStr);
            }
        })
    })
</script>

</body>
</html>